using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DataTransferObject;

namespace DataAccess
{
    public class clsTacGiaDAO:clsDataAccessHelper
    {
        // Fields
        private String tenTable;

        // Contructors
        public clsTacGiaDAO()
        {
            this.tenTable = "TACGIA";
        }
        #region Methods
        //-------------------------------------Lấy dữ liệu bảng Tác Giả-----------------------

        public DataTable SelectAll()
        {
            String sql;
            DataTable dt;
            try
            {
                sql = "SELECT * FROM " + this.tenTable;
                dt = new DataTable();
                dt = this.ExecuteQuery(sql);

                return dt;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        //-----------------------------------------------------------------------------//


        //-------------------------------------Thêm vào bảng Tác Giả-----------------------

        public bool Insert(clsTacGiaDTO tacgia)
        {
            String sql;
            bool check = false;

            try
            {
                sql = "INSERT INTO " + this.tenTable;
                sql += " values('";
                sql += tacgia.MaTG + "',N'";
                sql += tacgia.TenTG + "')";
                check = this.ExecuteNonQuery(sql);

                return check;
            }
            catch
            {
                return check;
            }
        }

        //-----------------------------------------------------------------------------//

        //-------------------------------------Xóa vào bảng Tác Giả-----------------------
        public bool Delete(clsTacGiaDTO tacgia)
        {
            String sql;
            bool check = false;

            try
            {
                sql = "DELETE ";
                sql += " FROM " + this.tenTable;
                sql += " WHERE MATG LIKE '" + tacgia.MaTG + "'";
                check = this.ExecuteNonQuery(sql);

                return check;
            }
            catch
            {
                return check;
            }
        }
        //-----------------------------------------------------------------------------//


        //-------------------------------------Sửa vào bảng Tác Giả-----------------------

        public bool Update(clsTacGiaDTO tacgia)
        {
            String sql;
            bool check = false;

            try
            {
                sql = "UPDATE " + this.tenTable;
                sql += " SET";
                sql += " TENTG = N'";
                sql += tacgia.TenTG + "'";
                sql += " WHERE MATG LIKE '";
                sql += tacgia.MaTG + "'";
                check = this.ExecuteNonQuery(sql);

                return check;
            }
            catch
            {
                return check;
            }
        }
        //-----------------------------------------------------------------------------//


        #endregion

    }
}
